package solutions.leetcode.normal;

import java.util.*;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/corporate-flight-bookings/">1109. 航班预订统计</a>
 */
public class Solution1109 {

    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] rst = new int[n];
        for (int[] booking : bookings) {
            rst[booking[0] - 1] += booking[2];
            if (booking[1] < n) {
                rst[booking[1]] -= booking[2];
            }
        }
        for (int i = 1; i < n; i++) {
            rst[i] += rst[i - 1];
        }
        return rst;
    }

    public static void main(String[] args) {
        Solution1109 solution = new Solution1109();
        int[][] val = new int[][] {
                new int[] {3, 4, 10},
                new int[] {1, 5, 10},
                new int[] {2, 5, 25}
        };
        int[] rst = solution.corpFlightBookings(val, 5);
        for (int[] v : val) {
            System.out.println(v[0] + ", " + v[1]);
        }
        for (int v : rst) {
            System.out.print(v + ", ");
        }
    }
}
